package com.administrator.cloudapplication.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.administrator.cloudapplication.R;
import com.administrator.cloudapplication.models.MoreModel;

import java.util.List;

/**
 * Created by Administrator on 2017/4/26.
 */

public class MoreAdapter extends BaseAdapter {
    private LayoutInflater mInflater;
    Context mContext;
    List<MoreModel> moreModelList;

    public MoreAdapter(Activity activity, List<MoreModel> ModelList) {
        mContext = activity;
        moreModelList = ModelList;
        mInflater = LayoutInflater.from(activity);
    }


    @Override
    public int getCount() {
        return moreModelList.size();
    }

    @Override
    public Object getItem(int i) {
        return moreModelList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    private class ViewHolder {
        ImageView img;
        TextView tv;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
       ViewHolder holder;
        if (view == null) {
            view = mInflater.inflate(R.layout.more_gridview, null);
            holder = new ViewHolder();
            holder.img = (ImageView) view.findViewById(R.id.iv_more);
            holder.tv = (TextView) view.findViewById(R.id.tv_more);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        MoreModel moreModel= (MoreModel) getItem(i);
        holder.img.setImageResource(moreModel.getImg());
        holder.tv.setText(moreModel.getText());
        return view;
    }
}
